/**
 * 数据操作服务
 */
export default class IndexService {
    constructor() {

    }

    /**
     * 获取列表
     * @param {*} 
     */
    async getLiveList(token) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "GET",
                url: `${API_PATH}/api/v1/live`,
                dataType: "json",
                data: { a: 1 },
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", token);
                },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }
    async getLiveList2(token) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "GET",
                url: `${API_PATH}/api/v1/MainRound`,
                dataType: "json",
                data: { a: 1 },
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", token);
                },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }
    async getLiveList3(options) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "GET",
                url: `${API_PATH}/api/v1/live`,
                dataType: "json",
                data: { HospitalRoleName: options.HospitalRoleName, start: options.start, length: options.length },
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", options.token);
                },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }
    async getHpList(token) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "GET",
                url: `${API_PATH}/api/v1/hospital`,
                dataType: "json",
                data: { a: 1 },
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", token);
                },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }
    //AD
    async getAD(token) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "GET",
                url: `${API_PATH}/api/v1/MainAD`,
                dataType: "json",
                data: { a: 1 },
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", token);
                },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }

    //订阅
    async getQR(token) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "GET",
                url: `${API_PATH}/api/v1/SubscripQRCode`,
                dataType: "json",
                data: { a: 1 },
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", token);
                },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }



    async getLiveListBykeyword(options) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "GET",
                url: `${API_PATH}/api/v1/live`,
                dataType: "json",
                data: options,
                // beforeSend: function(request) {
                //     request.setRequestHeader("Authorization", token);
                // },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }


    async getLiveFavorites(token, options) {
        return new Promise(function(resolve, reject) {
            $.ajax({
                type: "GET",
                url: `${API_PATH}/api/v1/LiveFavorites`,
                dataType: "json",
                data: options,
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", token);
                },
                success: function(result) {
                    resolve(result);
                },
                error: function() {
                    resolve({
                        code: 500,
                        message: "网络繁忙，请稍后再试"
                    });
                }
            });
        });
    }


}